﻿using System.Linq;
using Loki.Engine;
using Loki.UI.Win;
using Luna.Model;
using Luna.Model.Configuration;
using Luna.UI.Install;
using Luna.UI.Win.Install;

namespace Luna.UI.Win
{
    public class LunaWinBootStrapper : WinFormBootStrapper<LunaModel, MainViewModel>
    {
        public LunaWinBootStrapper(string P_Datasources, string P_Model, string P_ViewModel, string P_UI)
            : base(P_Datasources, P_Model, P_ViewModel, P_UI)
        {
        }

        public override void PreStart()
        {
            // first install
            if (ApplicationModel.Install.GetCurrentState() == InstallState.New)
            {
                ApplicationModel.Install.Install();
            }

            // create first user or logon
            if (ApplicationModel.Security.Users.Count() == 0)
            {
                FirstUserViewModel L_FirstUserVM = ContextHelper.GetViewModel<FirstUserViewModel>();
                ContextHelper.GetView<FirstUserView>(L_FirstUserVM).Show();
            }
            else
            {
                LogonViewModel L_LogonVM = ContextHelper.GetViewModel<LogonViewModel>();
                ContextHelper.GetView<LogonView>(L_LogonVM).Show();
            }
        }
    }
}
